package base;

/**
 * 策略模式和工厂模式结合到一起。
 *
 * @author Seon
 * @date 2022/11/5 13:10
 */
public class CashContext {
    private final BaseCashStrategy baseCashStrategy;

    public CashContext(int type) {
        switch (type) {
            case 1 -> baseCashStrategy = new CashReturn(300, 100);
            case 2 -> baseCashStrategy = new CashRebate(0.8);
            default -> baseCashStrategy = new CashNormal();
        }
    }

    /**
     * 其实就是加一层嘛，也可以这么理解，就是把调用返回结果的东西，又加了一层。
     */
    public double calculate(double price, int count) {
        return baseCashStrategy.acceptCash(price, count);
    }
}
